from django.contrib.contenttypes.models import ContentType
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Permission
from rest_framework.generics import GenericAPIView,ListAPIView
from rest_framework import mixins

from apps.meiduo_admin.serializers.permission import PermissionSerializer, ContentTypeSerialzier
from apps.meiduo_admin.utils import PageNum


class PermissionModelViewSet(ModelViewSet):
    """
    权限管理
    """
    # 指定查询集
    queryset = Permission.objects.all().order_by("id")
    # 指定序列化器
    serializer_class = PermissionSerializer
    # 指定分页器
    pagination_class = PageNum


# class CoententTypeAPIView(APIView):
#     """
#     使用一级视图APIView实现保存
#     """
#     def get(self,request):
#         # 查询
#         content = ContentType.objects.all()
#         # 返回结果
#         serializer = ContentTypeSerialzier(content,many=True)
#         return Response(serializer.data)


# class CoententTypeAPIView(GenericAPIView,mixins.ListModelMixin):
#     """
#     使用二级视图GenericAPIView实现保存
#     """
#     # 指定查询集合
#     queryset = ContentType.objects.all()
#     # 指定序列化器
#     serializer_class = ContentTypeSerialzier
#
#     def get(self,request):
#         return self.list(request)

class CoententTypeAPIView(ListAPIView):
    """
    使用三级视图ListAPIView实现保存
    """
    # 指定查询集合
    queryset = ContentType.objects.all()
    # 指定序列化器
    serializer_class = ContentTypeSerialzier

